import http from "../http-common";
import TutorialData from '../types/Tutorial';

const getTutorials = ()=>{
    return http.get<Array<TutorialData>>("/tutorials");
}

const findByTitle = (title:string)=>{
    return http.get<Array<TutorialData>>(`/tutorials?searchName=${title}`);
}

const getTutorial = (id:number)=>{
    return http.get<TutorialData>(`/tutorials/${id}`);
}

const create = (data:TutorialData) =>{
    return http.post<TutorialData>("/tutorials", data);
}

const update = (data:TutorialData, id:any) =>{
    return http.put<any>(`/tutorials/${id}`, data);
}

const remove = (id:any)=>{
    return http.delete<any>(`/tutorials/${id}`);
}

const TutorialService = {
    getTutorials,
    findByTitle,
    getTutorial,
    create,
    update,
    remove
}

export default TutorialService;